package com.woniuxy.joylifeforum.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.common.entity.CenterUser;
import com.woniuxy.common.utils.JWTUtils;
import com.woniuxy.joylifeforum.dto.UserMes;
import com.woniuxy.joylifeforum.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * h话题相关，通知 回复提醒 消息提醒
 */
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;
    /*
    检索通知提醒信息
     */
    @RequestMapping("/findRemind")
    public Object findRemind(HttpServletRequest request) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        List<UserMes> remindService = newsService.findRemindService(userId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", remindService);
        return result;
    }
    /*
    检索回复提醒信息
     */
    @RequestMapping("/replyRemind")
    public Object replyRemind(HttpServletRequest request,Integer page, Integer limit) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        PageInfo<Map<String, Object>> data = newsService.findReplyRemindService(page, limit, userId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
    获取关注的用户
     */
    @RequestMapping("/userContent")
    public Object userContent(HttpServletRequest request,String findUser) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        if("null".equals(findUser)){
            findUser=userId;
        }
        List<CenterUser> data = newsService.userContent(findUser);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
    获取用户粉丝
     */
    @RequestMapping("/userFans")
    public Object userFans(HttpServletRequest request,String findUser) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        if("null".equals(findUser)){
            findUser=userId;
        }
        List<Map<String, Object>> data = newsService.userFans(userId, findUser);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
    最近联系人
     */
    @RequestMapping("/latelyUser")
    public Object latelyUser(HttpServletRequest request) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        List<Map<String, Object>> data = newsService.findLatelyUser(userId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
    获取聊天记录
     */
    @RequestMapping("/chattingRecord")
    public Object chattingRecord(HttpServletRequest request,Integer page, Integer limit,String oppositeUserId) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> data = newsService.findChatting(page, limit, userId, oppositeUserId);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("data", data);
        return result;
    }
    /*
    聊天提交
     */
    @RequestMapping("/submitChat")
    public Object submitChat(HttpServletRequest request,String mes,String oppositeUserId) {
        //当前用户id
        //String userId="111";
        String userId = JWTUtils.getUserId(request.getHeader("token"));
        int status = newsService.submitChatService(userId, oppositeUserId, mes);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 200);
        result.put("mes", "OK");
        result.put("status", status);
        return result;
    }
}
